Skip to content

util: add hex colors support in styleText#61556

Open
araujogui wants to merge 9 commits intonodejs:mainfrom
araujogui:util/colorize-hex
Open

util: add hex colors support in styleText#61556
araujogui wants to merge 9 commits intonodejs:mainfrom
araujogui:util/colorize-hex

Conversation

@araujogui
Copy link
Copy Markdown
Member

Fixes #61543

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Jan 28, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.72%. Comparing base (0dfdec9) to head (c01e52b).
⚠️ Report is 38 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #61556   +/-   ##
=======================================
  Coverage   89.71%   89.72%           
=======================================
  Files         695      695           
  Lines      214154   214220   +66     
  Branches    41009    41018    +9     
=======================================
+ Hits       192132   192208   +76     
+ Misses      14075    14073    -2     
+ Partials     7947     7939    -8     
Files with missing lines Coverage Δ
lib/util.js 94.25% <100.00%> (+0.67%) ⬆️

... and 33 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test cases for invalid values.

@araujogui araujogui requested a review from Renegade334 January 29, 2026 18:50
@Renegade334 Renegade334 added the request-ci Add this label to start a Jenkins CI on a PR. label Feb 8, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 8, 2026
@nodejs-github-bot

This comment was marked as outdated.

@gurgunday gurgunday added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 8, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@aduh95 aduh95 added the semver-minor PRs that contain new features and should be released in the next minor version. label Feb 18, 2026
@aduh95 aduh95 added request-ci Add this label to start a Jenkins CI on a PR. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Feb 18, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Feb 18, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Member

@RafaelGSS RafaelGSS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't have a green CI yet, would you mind including hex to styleText benchmarks? We are working to improve that, and it would be interesting to see if this decreases performance.

Copilot AI review requested due to automatic review settings April 1, 2026 16:14
@araujogui araujogui force-pushed the util/colorize-hex branch from f943683 to c01e52b Compare April 1, 2026 16:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for passing hex color strings (e.g. #ffcc00, #fc0) to util.styleText() by emitting ANSI TrueColor (24-bit) foreground escape sequences, along with tests/docs/bench updates.

Changes:

  • Extend util.styleText() to recognize #RGB / #RRGGBB formats and generate 38;2;r;g;b ANSI sequences.
  • Add a new parallel test suite covering valid/invalid hex handling and env/TTY behavior.
  • Update util API docs and the existing styleText benchmark to include a hex format case.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
lib/util.js Implements hex color parsing and ANSI sequence generation inside styleText().
test/parallel/test-util-styletext-hex.js Adds comprehensive tests for hex parsing, composition with modifiers, invalid inputs, and env behavior.
doc/api/util.md Documents hex color support for util.styleText().
benchmark/util/style-text.js Adds a hex format option to benchmark styleText().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@araujogui
Copy link
Copy Markdown
Member Author

@araujogui at this point I'd probably recommend you checking if you're able to reproduce these errors, it is so consistently failing on windows-fanned that I'm starting to believe it is not flakiness but actual failures.
image

I've attached logs. And it is always these two contenders.

2,win11-arm64-COMPILED_BY-vs2022_clang-arm64.txt

1,win10-COMPILED_BY-vs2022_clang.txt

It's http and net tests that are flaky 😅

https://gist.github.com/araujogui/df02946a26166615c857f49cce19e73f

Rebased the PR again, maybe this solve the problem

@ovflowd ovflowd added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 2, 2026
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 2, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@ovflowd
Copy link
Copy Markdown
Member

ovflowd commented Apr 6, 2026

(╯°□°)╯︵ ┻━┻

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@ovflowd ovflowd added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 7, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Apr 7, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/61556
✔  Done loading data for nodejs/node/pull/61556
----------------------------------- PR info ------------------------------------
Title      util: add hex colors support in `styleText` (#61556)
Author     Guilherme Araújo <arauujogui@gmail.com> (@araujogui)
Branch     araujogui:util/colorize-hex -> nodejs:main
Labels     util, semver-minor, author ready, needs-ci, commit-queue-squash
Commits    9
 - util: colorize text with hex colors
 - util: nits
 - util: non-capturing regex
 - util: return buffer
 - doc: add history entry
 - doc: add final period
 - doc: profread
 - util: remove unused import
 - benchmark: add hex style
Committers 1
 - Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61556
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/61556
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Wed, 28 Jan 2026 01:00:57 GMT
   ✔  Approvals: 8
   ✔  - Michaël Zasso (@targos) (TSC): https://github.com/nodejs/node/pull/61556#pullrequestreview-3723149200
   ✔  - Jordan Harband (@ljharb): https://github.com/nodejs/node/pull/61556#pullrequestreview-3724564626
   ✔  - René (@Renegade334): https://github.com/nodejs/node/pull/61556#pullrequestreview-3769858571
   ✔  - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/61556#pullrequestreview-3770404667
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/61556#pullrequestreview-3822560259
   ✔  - Rafael Gonzaga (@RafaelGSS) (TSC): https://github.com/nodejs/node/pull/61556#pullrequestreview-3835624781
   ✔  - Claudio Wunder (@ovflowd): https://github.com/nodejs/node/pull/61556#pullrequestreview-4068182347
   ✔  - Chemi Atlow (@atlowChemi): https://github.com/nodejs/node/pull/61556#pullrequestreview-4016624350
   ✘  1 GitHub CI job(s) failed:
   ✘    - Cleanup artifacts: FAILURE (https://github.com/nodejs/node/actions/runs/23858701046/job/69559818402)
   ℹ  Last Full PR CI on 2026-04-07T11:13:20Z: https://ci.nodejs.org/job/node-test-pull-request/72532/
- Querying data for job/node-test-pull-request/72532/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/24082735401

@ovflowd
Copy link
Copy Markdown
Member

ovflowd commented Apr 7, 2026

You gotta be kidding me.... @aduh95 do you know how we can bypass https://github.com/nodejs/node/actions/runs/23858701046/job/69559818402? Seems like just a random Copilot error? IDK if retriggering Copilot would ignore that?

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ovflowd ovflowd added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Apr 7, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Apr 7, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/61556
✔  Done loading data for nodejs/node/pull/61556
----------------------------------- PR info ------------------------------------
Title      util: add hex colors support in `styleText` (#61556)
Author     Guilherme Araújo <arauujogui@gmail.com> (@araujogui)
Branch     araujogui:util/colorize-hex -> nodejs:main
Labels     util, semver-minor, author ready, needs-ci, commit-queue-squash
Commits    9
 - util: colorize text with hex colors
 - util: nits
 - util: non-capturing regex
 - util: return buffer
 - doc: add history entry
 - doc: add final period
 - doc: profread
 - util: remove unused import
 - benchmark: add hex style
Committers 1
 - Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/61556
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/61556
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Claudio Wunder <cwunder@gnome.org>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Wed, 28 Jan 2026 01:00:57 GMT
   ✔  Approvals: 8
   ✔  - Michaël Zasso (@targos) (TSC): https://github.com/nodejs/node/pull/61556#pullrequestreview-3723149200
   ✔  - Jordan Harband (@ljharb): https://github.com/nodejs/node/pull/61556#pullrequestreview-3724564626
   ✔  - René (@Renegade334): https://github.com/nodejs/node/pull/61556#pullrequestreview-3769858571
   ✔  - Gürgün Dayıoğlu (@gurgunday): https://github.com/nodejs/node/pull/61556#pullrequestreview-3770404667
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/61556#pullrequestreview-3822560259
   ✔  - Rafael Gonzaga (@RafaelGSS) (TSC): https://github.com/nodejs/node/pull/61556#pullrequestreview-3835624781
   ✔  - Claudio Wunder (@ovflowd): https://github.com/nodejs/node/pull/61556#pullrequestreview-4068182347
   ✔  - Chemi Atlow (@atlowChemi): https://github.com/nodejs/node/pull/61556#pullrequestreview-4016624350
   ✘  1 GitHub CI job(s) failed:
   ✘    - Cleanup artifacts: FAILURE (https://github.com/nodejs/node/actions/runs/23858701046/job/69559818402)
   ℹ  Last Full PR CI on 2026-04-07T13:03:37Z: https://ci.nodejs.org/job/node-test-pull-request/72532/
- Querying data for job/node-test-pull-request/72532/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/24086140240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[util] Allow styleText to take in hex colors